import { areaList } from '@vant/area-data';
class Location{
  text: string =''
  value: string = ''
}

class Area{
  text: string =''
  value: string = ''
  children:Array<Location> = new Array<Location>()  
}

export class Province{
  text: string =''
  value: string = ''
  children:Array<Area> = new Array<Area>()  
}


const tuiJian = ["香港","新加坡","曼谷","伦敦","澳门","吉隆坡","深圳","纽约市","安塔利亚","巴黎","伊斯坦布尔"," 罗马","迪拜","广州","普吉岛","麦加","芭堤雅","台北市","布拉格","上海","拉斯维加斯","迈阿密","巴塞罗那"," 北京","洛杉矶","维也纳","阿姆斯特丹","索非亚","马德里","奥兰多","胡志明市","利马","柏林","东京","华沙" ,"金奈","开罗","内罗毕","米兰","旧金山","布宜诺斯艾利斯","威尼斯","基辅","利沃夫","墨西哥城","都柏林","首尔","穆拉","孟买","登巴萨","德里","多伦多","博卡拉顿","棕榈滩","珠海","悉尼","慕尼黑","坎昆","卡波","圣卢卡斯","卢加诺","布加勒斯特","蓬塔卡纳","阿格拉","布鲁塞尔","尼斯","圣莫里茨","里斯本","卡斯卡伊斯","马拉喀什","雅加达" ,"巴厘岛","麦纳麦","河内","檀香山","马尼拉","奥克兰","暹粒","安曼","马耳他","阿布扎比","多哈","佛罗伦萨" ,"里约热内卢","墨尔本","华盛顿","利雅得","基督城","法兰克福","巴库","圣保罗","哈拉雷","南京","京都","克拉科夫","布里斯托尔","河江","尼科西亚","维尔纽斯","列支敦士登","摩纳哥","毛伊岛","檀香山","圣地亚哥","新奥尔良","芝加哥"," 基韦斯特","波士顿","阿斯彭","塞多纳","特柳赖德","西雅图","拉海纳","德斯坦","马里布","劳德代尔堡","比佛利山庄","圣莫尼卡" ,"奥斯汀","苏黎世","日内瓦","蒙特勒","巴塞尔","塔那那利佛","拉达克","萨尔塔","第比利斯","刚果","曼科拉","纳帕"," 查尔斯顿","斯托","布达佩斯","根特","安特卫普","热那亚","圣让卡普费拉","佛罗伦萨","萨格勒布","雅典","马德里"," 波尔图","利物浦","汉堡","斯德哥尔摩","哥本哈根","里加","圣克鲁斯","波哥大","巴拿马城","圣何塞","马那瓜","圣萨尔瓦多" ,"圣多明各","圣胡安","德班","迈尼拉"];

const cnProvinceList = new Array<Province>()

export const getRandList =():string=>{
  let value = Math.floor(Math.random() * tuiJian.length)
  if(value < 0){
    value = 0
  }
  if(value >= tuiJian.length){
    value = tuiJian.length - 1
  }
  return tuiJian[value]
}

export const getChinaProvince =():Array<Province>=>{
  if(cnProvinceList.length > 0){
    return cnProvinceList
  }
  const province_list = areaList.province_list
  for(const key in province_list){
    const value = province_list[key]
    cnProvinceList.push({text:value, value:key, children:[]})
  }
  return cnProvinceList
}

export const getCity = (pid:string):Array<Area>=>{
  const citys = areaList.city_list
  const cityList = new Array<Area>()
  const prefix = pid.slice(0,2)
  for(const key in citys){
    if(key.startsWith(prefix)){
      const value = citys[key]
      cityList.push({text:value, value:key, children:[]})
    }
  }
  return cityList
}

export const getCounty = (cid:string):Array<Location>=>{
  const list = new Array<Location>()
  const countrys = areaList.county_list
  const prefix = cid.slice(0,4)
  for(const key in countrys){
    if(key.startsWith(prefix)){
      const value = countrys[key]
      list.push({text:value, value:key})
    }    
  }
  return list
}